package com.sc.study.foundation.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sc.common.annotation.Log;
import com.sc.common.core.controller.BaseController;
import com.sc.common.core.domain.AjaxResult;
import com.sc.common.enums.BusinessType;
import com.sc.study.foundation.domain.ScViolationType;
import com.sc.study.foundation.service.IScViolationTypeService;
import com.sc.common.utils.poi.ExcelUtil;

/**
 * 违纪类型Controller
 * 
 * @author sc
 * @date 2022-03-14
 */
@RestController
@RequestMapping("/study/violationtype")
public class ScViolationTypeController extends BaseController
{
    @Autowired
    private IScViolationTypeService scViolationTypeService;

    /**
     * 查询违纪类型列表
     */
    @PreAuthorize("@ss.hasPermi('study:violationtype:list')")
    @GetMapping("/list")
    public AjaxResult list(ScViolationType scViolationType)
    {
        List<ScViolationType> list = scViolationTypeService.selectScViolationTypeList(scViolationType);
        return AjaxResult.success(list);
    }

    /**
     * 导出违纪类型列表
     */
    @PreAuthorize("@ss.hasPermi('study:violationtype:export')")
    @Log(title = "违纪类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScViolationType scViolationType)
    {
        List<ScViolationType> list = scViolationTypeService.selectScViolationTypeList(scViolationType);
        ExcelUtil<ScViolationType> util = new ExcelUtil<ScViolationType>(ScViolationType.class);
        util.exportExcel(response, list, "违纪类型数据");
    }

    /**
     * 获取违纪类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('study:violationtype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(scViolationTypeService.selectScViolationTypeById(id));
    }

    /**
     * 新增违纪类型
     */
    @PreAuthorize("@ss.hasPermi('study:violationtype:add')")
    @Log(title = "违纪类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScViolationType scViolationType)
    {
        return toAjax(scViolationTypeService.insertScViolationType(scViolationType));
    }

    /**
     * 修改违纪类型
     */
    @PreAuthorize("@ss.hasPermi('study:violationtype:edit')")
    @Log(title = "违纪类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScViolationType scViolationType)
    {
        return toAjax(scViolationTypeService.updateScViolationType(scViolationType));
    }

    /**
     * 删除违纪类型
     */
    @PreAuthorize("@ss.hasPermi('study:violationtype:remove')")
    @Log(title = "违纪类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(scViolationTypeService.deleteScViolationTypeByIds(ids));
    }
}
